package cn.acup.boot.config;

import java.nio.charset.Charset;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * web mvc 配置
 * @author alan.zhao
 */
@Configuration
public class WebAppConfig extends WebMvcConfigurationSupport  {  
	
	/**
	 * 拦截器
	 */
    @Override  
    public void addInterceptors(InterceptorRegistry registry) {  
        //注册自定义拦截器，添加拦截路径和排除拦截路径  
        registry.addInterceptor(new InterceptorConfig())
        	.excludePathPatterns("/login")
        	.addPathPatterns("/**");  
    }
    
    /**
     * 消息转换
     * 解决中文乱码
     */
    @Bean
    public HttpMessageConverter<String> responseBodyConverter(){
    	StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
    	return converter;
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    	super.configureMessageConverters(converters);
    	converters.add(responseBodyConverter());
    }
} 
